package main

import (
	"fmt"
	"io"
	"net"
)

const (
	pxyaddr = "192.168.60.126:4443"
	prvaddr = "127.0.0.1:80"
)

func main() {
	pxyconn, err := net.Dial("tcp", pxyaddr)
	if err != nil {
		fmt.Println("连接服务端失败:", err.Error())
		return
	}
	fmt.Println("已连接代理服务器")
	defer pxyconn.Close()
	prvconn, err := net.Dial("tcp", prvaddr)
	if err != nil {
		fmt.Println("连接服务端失败:", err.Error())
		return
	}
	fmt.Println("已连接内部服务器")
	defer prvconn.Close()
	Client(pxyconn, prvconn)
}

func Client(pxyconn net.Conn, prvconn net.Conn) {
	for {
		go func() {
			_, err := io.Copy(prvconn, pxyconn)
			if err != nil {
				fmt.Println("读取客户端数据错误:", err.Error())
			}
			//fmt.Println("复制字节：", c)
		}()
		go func() {
			_, err := io.Copy(pxyconn, prvconn)
			if err != nil {
				fmt.Println("读取客户端数据错误:", err.Error())
			}
			//fmt.Println("复制字节：", c)
		}()
	}
}
